Homer dreams of being a fashion reporter at a doughnut modeling show while doing his rounds at his job, but finds that Carl and Lenny have already eaten all of the real donuts (and chucked the rest at an old man for fun). Desperate, he claims he'd sell his soul for a donut, and at that instant, the Devil (who, surprisingly, is Ned Flanders) appears and offers to give him one. Homer signs a contract and is given a donut. But before he finishes it, he realizes that as long as he doesn't do so, the contract is voided. The Devil vows Homer will go to Hell sooner or later before disappearing.
That night, a half-asleep Homer goes to grab a midnight snack and thoughtlessly eats the last piece of the donut; the Devil appears and starts to suck him into Hell. The family awakes in the commotion and Lisa begs the Devil for a fair trial; he grudgingly agrees to this but demands that Homer spend a day in Hell. Down below, Homer finds himself chopped into pieces and given an ironic punishment by being force-fed all the donuts in the world (he manages to eat the whole supply, much to the torture technician demon's confusion, as James Coco went insane in 15 minutes from doing the same thing Homer did).
Meanwhile the family hires Lionel Hutz to represent him in the trial. Midnight comes and the Devil, along with The Grim Reaper as a judge, appears along with Homer (bound in a fire cage). The Devil and Hutz barter on specific terms before the trial begins: Hutz for bathroom breaks, the Devil on his pick of the jury, which turns out to include some of the most notorious people from history: Benedict Arnold, Lizzie Borden, Richard Nixon (who, at the time of the episode, was still alive and was only on the jury because the Devil did a favor for him, either to be President or to not be implicated in the Watergate scandal), John Wilkes Booth, Edward Teach (a.k.a. Blackbeard the Pirate), John Dillinger, and the starting line-up of the 1976 Philadelphia Flyers ("The Broad Street Bullies"). The trial doesn't go well; when the Devil offers proof of his deal, Hutz excuses himself to go to the bathroom and flees out the window.
Just as it looks that Homer will be condemned to Hell, Marge comes in with a photo album and shows everyone their wedding photo (which was in an emergency room as Homer ate the entire wedding cake...before the wedding). On the back of the photo is a declaration Homer made pledging his soul to Marge. The jury agrees that Homer's soul belongs to her, and he's freed, but the Devil, sore at being cheated, turns his head into a donut as punishment. Now Homer can't resist munching on himself, and most of the town's cops are waiting outside with coffee cups.